#ifndef TC_MASIMPLE_HPP
#define TC_MASIMPLE_HPP

/** \file MASimple.hpp
 * Definition for the MASimple function template.
 *
 * (C) Copyright 2003-2006 by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: MASimple.hpp 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */

#include "TA.hh"
#include "DBC.hpp"
#include "CircArray.hpp"

namespace TC {

  //! Simple moving average function.
  TC_EXPORT template <typename InputIterator,
                      typename OutputIterator,
                      class Adaptor>
  void MASimple(InputIterator fromPos,
                InputIterator fromEnd,
                OutputIterator toPos,
                const unsigned period,
                const Adaptor adaptor)
  {
    TC_PRE_CONDITION(period > 0);
    
    CircArray<TAfp_t> ma_arr(period);

    for(; fromPos!=fromEnd; ++fromPos) {
      ma_arr.push(adaptor(*fromPos));
      *toPos++ = ma_arr.avg();
    } // end for
    
  }


} // end namespace


#endif /* Include guard */
